$(function(){
	//密码的显示隐藏
	var $selector = $('#switch');
	$selector.off('tap').on('tap',function(e){
		var $this=$(this);
		$this.hasClass('bg-hide')?$this.addClass('bg-show').removeClass('bg-hide').prev('input').attr({'type':'text'}):$this.addClass('bg-hide').removeClass('bg-show').prev('input').attr({'type':'password'});
		e.preventDefault();
        return false;   
	})
	var $agreeProtocolLabel=$("#gma-label");
    $agreeProtocolLabel.off("tap").on("tap",function(e){
        var $this=$(this);          
        $this.hasClass("gma-label-init")?$this.removeClass("gma-label-init").addClass("gma-label-checked"):$this.removeClass("gma-label-checked").addClass("gma-label-init")
    });

var sendData={};
var globalHost=common.globalHost;
var loginPort=common.loginPort;
var loginPortUrl=globalHost+loginPort;
var registerPort=common.registerPort;
var url=globalHost+registerPort;
var resultGetTestCode=baseInfoForm.getTestCode({targetSelector:baseInfoForm.getCode,type:"register"});
baseInfoForm.submit.off('tap').on('tap',function(e){
    var $this=$(this);
    var checkCase=$this.hasClass("act-ago");
        sendData=common.getSendDataByForm(baseInfoForm.form);
    var resultAgreeProtocal=baseInfoForm.agreeProtocol({targetSelector:$agreeProtocolLabel,noticeMsg:"请勾选注册协议"});
    var resultPassword=baseInfoForm.testPassword({targetSelector:baseInfoForm.password,noticeMsg:"密码"});
    var resultTestCode=baseInfoForm.testMobileCode({targetSelector:baseInfoForm.testCode,noticeMsg:"请输入验证码"});
    var resultTel=baseInfoForm.regTestTel({targetSelector:baseInfoForm.tel,noticeMsg:"手机号",length:11});
    if(!!checkCase&&!!resultTel&&!!resultTestCode&&!!resultPassword&&!!resultAgreeProtocal){
        $this.removeClass("act-ago").addClass("acted-yet");
        baseInfoForm.formPost({
            sendData:sendData,
            url:url,
            resSuccess:function(data){  
                baseInfoForm.formPost({
                    sendData:sendData,
                    url:loginPortUrl,
                    resSuccess:function(data){
                        actedStyle ();
                        baseInfoForm.form[0].reset();
                        var data=data.res.data;
                        // console.log(data)
                        common.setLocalStorage("H5-agentInfo",JSON.stringify(data));
                        window.location.href='registerInfo.html';
                    }
                });   
            },
            resFailed:function(data){
                 actAgoStyle (); 
            }
       }); 
    }else{
        console.log("不准发送ajax");
    }
    e.preventDefault();
        return false;     
}); 
function actedStyle () {
    baseInfoForm.submit.removeClass("act-ago").addClass("acted-yet");
}
function actAgoStyle () {
    baseInfoForm.submit.removeClass("acted-yet").addClass("act-ago");
}
//点击按钮显示协议
$('#alert-dialog').on("click",function() {
    $('.protocol-wrapper').show();
});
$('.protocol-close').on("click",function() {
    $(this).parent().hide();
});
})
